More scragglers from last merge.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 12 May 2006 21:09:05 +0000 (21:09 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 12 May 2006 21:09:05 +0000 (21:09 +0000)
gpsbabel/Makefile.in
gpsbabel/defs.h
gpsbabel/route.c
gpsbabel/units.c [new file with mode: 0644]

index 8a7f66da558189d5e5039414747750f2014cd00d..75b4fbc61a458bccd4f38309c07444df4e3bf6be 100644 (file)
@@ -11,11 +11,7 @@ DOCVERSION=development
 # VERSIONU=1_2_7
 # VERSIOND=1.2.7
 
-# If you do not have libexpat and you have no use for reading any input
-# type that is XML-ish (i.e. gpx or geocaching.com's/loc) you can uncomment
-# INHIBIT_EXPAT and coment out LIBEXPAT on just to get a build working quickly.
-# INHIBIT_EXPAT=-DNO_EXPAT
-LIBEXPAT=@EXPAT_LIB@  # -lefence
+#EXTRA_LIBS -lefence
 
 # Space is significant, because MSVC wants no space between switch and arg (-Fofoo.o)
 # but cc/gcc does:
@@ -31,7 +27,7 @@ OPTIMIZATION=-O $(EXTRA_OPTIMIZATION)
 DEBUGGING=-g $(EXTRA_DEBUGGING)
 # add -DDEBUG_MEM to turn on memory allocation logging
 GBCFLAGS=$(EXTRA_CFLAGS) $(DEBUGGING) -I. -I@srcdir@/coldsync \
-       $(INHIBIT_USB) $(OPTIMIZATION) @CFLAGS@
+       $(OPTIMIZATION) @CFLAGS@
 INSTALL_TARGETDIR=/usr/local/
 
 # OTHER_ROOT=/opt/local        # For DarwinPorts on OSX
@@ -73,7 +69,7 @@ SHAPE=shapelib/shpopen.o shapelib/dbfopen.o
 LIBOBJS = queue.o route.o waypt.o filter_vecs.o util.o vecs.o mkshort.o \
           csv_util.o strptime.o grtcirc.o vmem.o util_crc.o xmlgeneric.o \
           uuid.o formspec.o xmltag.o cet.o cet_util.o fatal.o rgbcolors.o \
-         inifile.o garmin_fs.o gbsleep.o \
+         inifile.o garmin_fs.o gbsleep.o units.o @GBSER@ \
        $(COLDSYNC) $(GARMIN) $(JEEPS) $(SHAPE) $(FMTS) $(FILTERS)
 OBJS = main.o globals.o $(LIBOBJS)
 
@@ -89,7 +85,7 @@ WEB=../babelweb/
 all: gpsbabel@EXEEXT@
 
 gpsbabel@EXEEXT@: $(OBJS)
-       @CC@  $(CFLAGS) $(OBJS) @LIBS@ @USB_LIBS@ $(LIBEXPAT) $(OUTPUT_SWITCH)$@
+       @CC@  $(CFLAGS) $(OBJS) @LIBS@ @EXPAT_LIB@ @USB_LIBS@ $(OUTPUT_SWITCH)$@
 
 Makefile: Makefile.in config.status
        CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status 
index b8fe32c5f77289d241f80dd96959164fbb22a51b..4eec8ca4cd878fe82bd1870ceb9299e8414d3529 100644 (file)
@@ -356,8 +356,8 @@ typedef struct {
        double  distance_meters;
        double  max_alt;
        double  min_alt;
-       double  max_spd;
-       double  min_spd;
+       double  max_spd;        /* Meters/sec */
+       double  min_spd;        /* Meters/sec */
        time_t  start;          /* Min time */
        time_t  end;            /* Max time */
 } computed_trkdata;
@@ -552,6 +552,7 @@ typedef enum {
        ff_cap_read = 1,
        ff_cap_write = 2
 } ff_cap;
+
 #define FF_CAP_RW_ALL \
        { ff_cap_read | ff_cap_write, ff_cap_read | ff_cap_write, ff_cap_read | ff_cap_write }
 
@@ -745,6 +746,19 @@ double degrees2ddmm(double deg_val);
 unsigned long get_crc32(const void * data, int datalen);
 unsigned long get_crc32_s(const void * data);
 
+/*
+ *  From units.c
+ */
+typedef enum {
+       units_unknown = 0,
+       units_statue = 1,
+       units_metric =2
+} fmt_units;
+
+int    fmt_setunits(fmt_units);
+double fmt_distance(const double, char **tag);
+double fmt_speed(const double, char **tag);
+
 /*
  * From gbsleep.c
  */
index 609558c7dd7d6a212aaaf58ed4e0d74613eef580..cb0a4fb0f5a652d68e91537e7cbf4978fafd46d5 100644 (file)
@@ -468,8 +468,8 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap)
        first.latitude = 0;
        first.longitude = 0;
        first.creation_time = 0;
-       tdata->min_alt = 999999;
-       
+       tdata->min_alt =  999999999;
+       tdata->max_alt = -999999999;
 
        QUEUE_FOR_EACH((queue *)&trk->waypoint_list, elem, tmp) {
                time_t timed;
@@ -490,16 +490,16 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap)
                dist = radtometers(gcdist(plat, plon, tlat, tlon));
 
                /* 
-                * Avoid that 6300 miles as we move from 0,0.
+                * Avoid that 6300 mile jump as we move from 0,0.
                 */
                if (plat && plon) {
                        tdata->distance_meters += dist;
                }
 
                /*
-                * If we've moved, recompute speed.
+                * If we've moved as much as a meter, recompute speed.
                 */
-               if (timed) {
+               if (timed && (dist > 1)) {
                        this->speed = dist / labs(timed);
                        if (this->speed > tdata->max_spd) {
                                tdata->max_spd = this->speed;
diff --git a/gpsbabel/units.c b/gpsbabel/units.c
new file mode 100644 (file)
index 0000000..0b8f93b
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+    Display scaled distances in 'local' units.
+    Copyright (C) 2006 Robert Lipe, robertlipe@usa.net
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+
+#include "defs.h"
+
+static int units = units_statue;
+
+int 
+fmt_setunits(fmt_units u)
+{
+       switch (u) {
+       case units_statue:
+       case units_metric:
+               units = u;
+               return 0;
+       default:
+               return 1;
+       }
+}
+
+double
+fmt_distance(const double distance_meters, char **tag)
+{
+       double d;
+
+       switch (units) {
+       case units_statue: 
+               d = METERS_TO_FEET(distance_meters);
+               if (d < 5280) {
+                       *tag = "ft";
+               } else  {
+                       d = METERS_TO_MILES(distance_meters);
+                       *tag = "mi";
+               }
+               break;
+       case units_metric:
+               d = distance_meters;
+               if (d < 1000) {
+                       *tag = "meters";
+               } else {
+                       d = d / (double) 1000.0;
+                       *tag = "km";
+               }
+               break;
+               
+       default: 
+               fatal("not done yet");
+               break;
+       }
+
+       return d;
+}
+
+double
+fmt_speed(const double distance_meters_sec, char **tag)
+{
+       double d;
+
+       switch (units) {
+       case units_statue:
+               d = METERS_TO_MILES(distance_meters_sec) * SECONDS_PER_HOUR ;
+               *tag = "mph";
+               break;
+       case units_metric:
+               d = distance_meters_sec * SECONDS_PER_HOUR;
+               *tag = "meters/hour";
+               if (d > 1000.0) {
+                       d /= 1000.0;
+                       *tag = "km/hour";
+               }
+               break;
+       default: fatal("not done yet");
+
+       }
+       return d;
+}